package com.ts.api.common.context;

import com.ts.api.common.constant.channel.ChannelVersionEnum;
import com.ts.api.module.channel.entity.po.ChannelPO;

/**
 *  渠道上下文
 */
public class ChannelContext {

    public static final ThreadLocal<ChannelPO> CHANNEL = new ThreadLocal<>();

    /**
     * 获取渠道唯一标识
     *
     * @return
     */
    public static String getUnicode() {
        return CHANNEL.get().getUniqueCode();
    }

    /**
     * 获取对象
     *
     * @return
     */
    public static ChannelPO get() {
        return CHANNEL.get();
    }

    /**
     * 获取id
     *
     * @return
     */
    public static Long getId() {
        return CHANNEL.get().getId();
    }

    /**
     * 是否为某个版本号
     *
     * @return boolean
     */
    public static boolean hasVersion(ChannelVersionEnum versionEnum) {
        Integer version = get().getVersion();
        return versionEnum.getVersion().equals(version);
    }
}
